package com.dl7.player.media;

import com.dl7.player.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.app.Context;
import java.util.List;

/**
 * Created by Rukey7 on 2016/10/29.
 */

public class AdapterMediaQuality extends BaseListAdapter<MediaQualityInfo> {


    public AdapterMediaQuality(Context context, List<MediaQualityInfo> datas) {
        super(context, datas);
    }

    public AdapterMediaQuality(Context context) {
        super(context);
    }


    private void _cleanSelected() {
        for (MediaQualityInfo info : mDatas) {
            if (info.isSelect()) {
                info.setSelect(false);
            }
        }
    }

    public void setMediaQuality(int quality) {
        for (MediaQualityInfo info : mDatas) {
            if (info.getIndex() == quality) {
                if (!info.isSelect()) {
                    _cleanSelected();
                    info.setSelect(true);
                    notifyDataChanged();
                }
                return;
            }
        }
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        if (component == null) {
            component =
                    LayoutScatter.getInstance(mContext)
                            .parse(ResourceTable.Layout_adapter_media_quality, componentContainer, false);
        }
        Text qualityDesc =
                (Text) component.findComponentById(ResourceTable.Id_tv_media_quality);
        qualityDesc.setText(mDatas.get(i).getDesc());
        qualityDesc.setSelected(mDatas.get(i).isSelect());
        return component;
    }
}
